package com.example.mylock;

/**
 * description: MyUnreentrantLock <br>
 * date: 2021/3/1 09:48 <br>
 *
 * @author: ZhangYixin <br>
 * version: 1.0 <br>
 */
public class MyUnreentrantLock {

    private static boolean isLock = false;

    public synchronized void lock() throws InterruptedException {
        System.out.println("进入lock方法上锁"+Thread.currentThread().getName());

        while (isLock){
            System.out.println("当前有人持有锁，进入wait等待"+Thread.currentThread().getName());

            wait();
        }
        isLock = true;

    }

    public void unlock(){
        System.out.println("进入unLock方法解锁"+Thread.currentThread().getName());
        isLock = false;
        notify();
    }
}
